package annotation.student.util;

import annotation.student.annotaion.StudentInfo;

import java.lang.reflect.Field;

/**
 * @author 标记
 * @date 2021/2/4
 */
public class StudentUtil {

    public static  void getStudent(Class<?> clazz) {
        String strStudentName="学生名字：";
        String strStudentScore="学生成绩：";
        String strStudentInfo="学生信息：";

        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields) {
            // 判断是否存在注解
            if (field.isAnnotationPresent(StudentInfo.class)) {
                StudentInfo studentInfo = (StudentInfo) field.getAnnotation(StudentInfo.class);
                strStudentInfo=strStudentInfo+"学生id："+studentInfo.id()+",学生班级："+studentInfo.studentClass().toString();
                System.out.println(strStudentInfo);
            }
        }
    }
}
